package com.avic.rong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avic.rong.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Creater: Created by wangyz on 2017/3/10.
 * Email: 936804097@qq.com
 */

public class ResouceAdapter extends BaseAdapter {


    private Context mContext;
    private List<String> data = new ArrayList<>();


     public ResouceAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<String> list) {
        data.clear();
        data.add("1");
        data.add("2");
        data.add("3");
        data.add("4");
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int postion) {
        return data.get(postion);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        ResourceViewHolder cePingViewHolder = null;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.view_resouce, viewGroup, false);
            cePingViewHolder = new ResourceViewHolder(convertView);
            convertView.setTag(cePingViewHolder);
        } else {
            cePingViewHolder = (ResourceViewHolder) convertView.getTag();
        }


        if (position == 0){
            cePingViewHolder.img_authority_pic.setImageResource(R.mipmap.gjb_gjjybz);
        }else if(position == 1){
            cePingViewHolder.img_authority_pic.setImageResource(R.mipmap.hb_hybz);
        }else if(position == 2){
            cePingViewHolder.img_authority_pic.setImageResource(R.mipmap.gb_gjbz);
        }else if(position == 3){
            cePingViewHolder.img_authority_pic.setImageResource(R.mipmap.asd_stan);
        }

//        if (!TextUtils.isEmpty(comeFrom) && comeFrom.equals(FragmentMain.SOURCE_FROM_FRAGMENT_MAIN)) {//从FragmentMain过来
//            GlideUtil.getInstance().loadCornerImageFitCenter(mContext, cePingViewHolder.img_authority_pic, mData.get(position).getPosidImg(),
//                    (DensityUtils.getWindowWidth(mContext) - DensityUtils.dp2px(mContext, 10) * 3) / 2,
//                    DensityUtils.dp2px(mContext, 86), DensityUtils.dp2px(mContext, 2), R.mipmap.icon_ceping_def);
//        } else {
//            GlideUtil.getInstance().loadCornerImageFitCenter(mContext, cePingViewHolder.img_authority_pic, mData.get(position).getTitleImg(),
//                    (DensityUtils.getWindowWidth(mContext) - DensityUtils.dp2px(mContext, 10) * 3) / 2,
//                    DensityUtils.dp2px(mContext, 86), DensityUtils.dp2px(mContext, 2), R.mipmap.icon_ceping_def);
//        }

//        cePingViewHolder.tv_authority_tag.setTypeface(MyApplication.getAppLightTypeface());
//        if (keyWord != null) {
//            cePingViewHolder.tv_authority_tag.setText(Html.fromHtml(mData.get(position).getTitle().replace(keyWord, StringUtils.redWord(keyWord))));
//        } else {
//            cePingViewHolder.tv_authority_tag.setText(mData.get(position).getTitle());
//        }

//        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) cePingViewHolder.ll_content.getLayoutParams();
//        if (position % 2 == 0) {
//            layoutParams.setMargins(0, 0, DensityUtils.dip2px(mContext, 5), 0);
//        } else {
//            layoutParams.setMargins(DensityUtils.dip2px(mContext, 10), 0, 0, 0);
//        }
//        cePingViewHolder.ll_content.setLayoutParams(layoutParams);

        return convertView;
    }


    class ResourceViewHolder {

        @BindView(R.id.ll_content)
        LinearLayout ll_content;
        @BindView(R.id.img_authority_pic)
        ImageView img_authority_pic;
        @BindView(R.id.tv_authority_tag)
        TextView tv_authority_tag;

        public ResourceViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
